const ts = require('typescript');
function compile(fileNames, options) {
  if (fileNames.length === 0) {
    console.error('No input files');
    return;
  }
  let program = ts.createProgram(fileNames, options);
  let emitResult = program.emit();
  let allDiagnostics = ts
    .getPreEmitDiagnostics(program)
    .concat(emitResult.diagnostics);
  allDiagnostics.forEach((diagnostic) => {
    if (diagnostic.file) {
      let { line, character } = ts.getLineAndCharacterOfPosition(
        diagnostic.file,
        diagnostic.start,
      );
      let message = ts.flattenDiagnosticMessageText(
        diagnostic.messageText,
        '\n',
      );
      console.log(
        `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`,
      );
    } else {
      console.log(
        ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'),
      );
    }
  });
  let exitCode = emitResult.emitSkipped ? 1 : 0;
  console.log(`Process exiting with code '${exitCode}'.`);
  process.exit(exitCode);
}
compile(process.argv.slice(2), {
  noEmitOnError: true,
  noImplicitAny: true,
  // target: ts.ScriptTarget.ES2015,
  module: ts.ModuleKind.Node16,
});
